package com.lemon.smartsafety.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.utils.CommonUtil;
import com.lemon.smartsafety.view.dialog.adapt.SingleTextAdapt;



/**
 * 项目名称：teacher
 * 类描述：
 * 创建人：Administrator
 * 创建时间：2015/8/13 0013 下午 3:09
 * 修改人：Administrator
 * 修改时间：2015/8/13 0013 下午 3:09
 * 修改备注：
 */
public class DialogChoice {

    private Context mContext;
    private ListView listView;
    private TextView txtCancel;

    private String[] stringContentList;
    private ClickBackInterface mClickBackInterface;
    private SingleTextAdapt singleTextAdapt;

    private Dialog dialog;

    public interface ClickBackInterface {
        public void callBackFunction(View view, int i);

    }


    public DialogChoice(Context mContext) {
        this.mContext = mContext;
    }


    /**
     *** 初始化
     */
    public void init(Context context, String strCancel, ClickBackInterface clickBackInterface, String... stringList) {

        stringContentList=stringList;

        mClickBackInterface=clickBackInterface;

        dialog = new Dialog(context, R.style.dialog_style);
        dialog.setContentView(R.layout.dialog_choice);
        Window win = dialog.getWindow();
        win.setGravity(Gravity.BOTTOM);
        win.setWindowAnimations(R.style.ActionSheetDialogAnimation);
        win.setLayout(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        dialog.setCanceledOnTouchOutside(true);

        txtCancel = (TextView)dialog.findViewById(R.id.txt_cancel);
        listView = (ListView)dialog.findViewById(R.id.list);


        if(!CommonUtil.strIsEmpty(strCancel)){
            txtCancel.setText(strCancel);
        }

        txtCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //mClickBackInterface.callBackFunction(txtCancel, -1);
                dialog.dismiss();
            }
        });


        if(stringContentList.length!=0){

            singleTextAdapt=new SingleTextAdapt(mContext,stringContentList);
            listView.setAdapter(singleTextAdapt);
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {

                    mClickBackInterface.callBackFunction(listView, position);
                    dialog.dismiss();
                }
            });

        }else{
            return;
        }

        if(dialog!=null)
        dialog.show();

    }






}